package modele;

import java.util.ArrayList;

public class FairScheduler extends Scheduler {

	int index;

	public FairScheduler() {
		this.list = new ArrayList<Action>();
		this.index = 0;
	}

	@Override
	public boolean isReady() {
		return list.get(index).isReady();
	}

	@Override
	public boolean isFinished() {
		for (Action a : list)
			if (!a.isFinished()) {
				// System.out.println(a.toString() + " has not finished.");
				return false;
			}
		return true;
	}

	@Override
	public void reallyDoStep() {
		System.out.println(list.get(index).toString() + "'s turn");
		list.get(index).doStep();
		do {
			index = index + 1;
			if (index == list.size())
				index = 0;
		} while (!isFinished() && list.get(index).isFinished());

	}

}
